//
//  AppDelegate.m
//  TcpServer
//
//  Created by scarlettsun on 12-7-28.
//  Copyright (c) 2012年 tencent. All rights reserved.
//

#import "AppDelegate.h"
#import "MiniSocket.h"
#import "MysqlDB.h"

extern NSString * hostIp;
extern NSString * userName;
extern NSString * password;
extern NSString * dbName;

@implementation AppDelegate

@synthesize window = _window;
@synthesize mainSocketDelegate;
@synthesize checkHeartDelegate;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
  
    //从plist中读取默认偏好设置
    NSString *path = [[NSBundle mainBundle] pathForResource:@"defaults" ofType:@"plist"];
    NSDictionary *defaultValues = [[NSDictionary alloc] initWithContentsOfFile:path];
    [[NSUserDefaults standardUserDefaults]registerDefaults:defaultValues];
    [[NSUserDefaults standardUserDefaults]synchronize];
    
    hostIp = [[NSUserDefaults standardUserDefaults] stringForKey:@"SQLHOST"];
    hostIp = hostIp == nil ?  SERVER_NAME : hostIp;
    userName = [[NSUserDefaults standardUserDefaults] stringForKey:@"SQLUSER"];
    userName = userName == nil ?  USER_NAME : userName;
    password = [[NSUserDefaults standardUserDefaults] stringForKey:@"SQLPASSWORD"];
    password = password == nil ?  PASS_WORD : password;
    dbName = [[NSUserDefaults standardUserDefaults] stringForKey:@"SQLDATABASE"];
    dbName = dbName == nil ?  DATA_BASE : dbName;
    
    /*
     check the heart beat queue;
     */
    self.checkHeartDelegate =  [[CheckHeartBeat alloc] init];
    [self.checkHeartDelegate doOnlineCheck];
    
    /*
     do packet dispatch;
     */
    /*self.packetDispacthCenter =  [[PacketDispatchCenter alloc] init];
    [self.packetDispacthCenter doPacketDispatch];   */
    
    /* 
     create main socket
     */  
    self.mainSocketDelegate = [[MainSocketDelegate alloc] init];
    [self.mainSocketDelegate startStop];
    
}

@end
